import 'dart:async';

import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'controller_import.dart';

abstract class BaseListController<M> extends BaseController /*with StateMixin<List<M>>*/{
  bool isFresh = true;
  int page = 0;
  final int size = 20;
  EasyRefreshController refreshController = EasyRefreshController();
  final mList = RxList<M>([]);


  @override
  void onClose() {
    beforeDispose();
    super.onClose();
    onDestroy();
    refreshController.dispose();
  }

  void callRefresh(){
//    Future.delayed(Duration(seconds: 2),(){
//      refreshController.callRefresh();
      loadData();
//    });
  }

  void loadData() async{
    getList((value){
      List<M> data = value;
      final noMore = ListUtil.isEmpty(data) || data.length < size;
      if(isFresh){
        isFresh = false;
        mList.clear();
        refreshController.finishRefresh(noMore: noMore);
      }else{
        refreshController.finishLoad(noMore: noMore);
      }
      mList.addAll(data);
//      change(mList, status: RxStatus.success());
      LiLog.d('BaseListController mList.length = '+mList.length.toString());
      return;
    });

  }

  //获取列表数据
  void getList(FutureOr<M> onValue(List<M> value));
}